// xc_lshop/distr/shareholder/statistics.js
var distr_shareholderbill = require('../model/distribution_shareholder')
var wxCharts = require('../../../xc/sys/wxcharts');
var lineChart = null;
// var util=require('../../../utils/util.js')

Page({
  mixins: [require('../../../xc/mixins/basicMixin')],

  /**
   * 页面的初始数据
   */
  data: {
    searchmodel:{
      navstatus:9,
    }
  },
  xcloaddata: function (options, config) {
    this.getbasic()
  },
  getbasic(){
    var that = this;
    distr_shareholderbill.dividendstatistics(this.data.searchmodel).then(function (rst) {
      console.log("rst")
      console.log(rst)
      if (rst["status"] == 1) {
        that.setData({
          'xcmodel': rst["obj"]
        })
        that.line()
      }
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {

  },
   //导航改变
   onNavChange(e){
    var update={}
    if(e.detail.navstatus){
     update['searchmodel.navstatus']=e.detail.navstatus
    }
    if(e.detail.start){
     update['searchmodel.starttime']=e.detail.start
    }
    if(e.detail.end){
     update['searchmodel.endtime']=e.detail.end
    }
    if(e.detail.year){
      update['searchmodel.year']=e.detail.year
     }
    this.setData(update)
    this.getbasic()
    // this.getpagelist(1)
   },
   line(){
    var windowWidth = 320;
    try {
        var res = wx.getSystemInfoSync();
        windowWidth = res.windowWidth - 15;
    } catch (e) {
        console.error('getSystemInfoSync failed!');
    }
    
    var simulationData = this.data.xcmodel.linedata;
    // console.log("simulationData")
    // console.log(simulationData)
    lineChart = new wxCharts({
      canvasId: 'lineCanvas',
      type: 'line',
      color: ['#FF8B58','#ACD97C'],
      categories: simulationData.categories,
      animation: true,
      // background: '#f5f5f5',
      series: [{
          name:"分红",
          data: simulationData.data.bonus,
          color:"#FF8B58",
          format: function (val, name) {
            return val+ '元';
          }
        },
        {
          name:"毛利",
          data: simulationData.data.profit,
          color:"#ACD97C",
          format: function (val, name) {
            return val+ '元';
          }
        },
      ],
      xAxis: {
        disableGrid: true
      },
      yAxis: {
        title: simulationData.title,
        format: function (val) {
          return val.toFixed(2);
        },
        min: 0
      },
      width: windowWidth,
      height: 200,
      dataLabel: false,
      dataPointShape: true,
      extra: {
        lineStyle: 'curve'
      }
    });
  },
  touchHandler: function (e) {

    lineChart.showToolTip(e, {
      format: function (item, category) {
        return category + ' ' + item.name + ':' + item.data
      }
    });
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})